﻿using System;
using System.ServiceModel;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Utilities;
using PdfConverter;

namespace SJKP.PDFConversion.Service
{
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Multiple, IncludeExceptionDetailInFaults = true)]
    public class OCRServiceApplication : SPIisWebServiceApplication
    {
        [Persisted]
        private string pdfConverterType;

        public IPdfConverter PdfConverter 
        {
            get { return Activator.CreateInstance(Type.GetType(PdfConverterType)) as IPdfConverter; }
        }

        public string PdfConverterType
        {
            get { return pdfConverterType; }
            set { pdfConverterType = value; }
        }

        protected override string InstallPath
        {
            get { return SPUtility.GetGenericSetupPath(@"WebServices\SJKP.OCR"); }
        }

        protected override string VirtualPath
        {
            get { return "OCRService.svc"; }
        }

        public override string TypeName
        {
            get
            {
                return "OCR Service Application";
            }
        }

        protected override string DefaultEndpointName
        {
            get { return "http"; }
        }

        public override SPAdministrationLink ManageLink
        {
            get
            {
                return GetManageLink();
            }
        }

        public override SPAdministrationLink PropertiesLink
        {
            get
            {
                return GetManageLink();
            }
        }

        

        public OCRServiceApplication() { }

        public OCRServiceApplication(string name, OCRService service, SPIisWebServiceApplicationPool application)
            : base(name, service, application)
        {

        }

        private SPAdministrationLink GetManageLink()
        {
            return new SPAdministrationLink(string.Format("/_admin/SJKP.OCR/Manage.aspx?id={0}", this.Id));
        }        
    }
}
